package com.gbb.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

import java.util.List;

public abstract class SimpleExpandableAdapter<T> extends BaseExpandableListAdapter {

    protected Context mContext;

    protected LayoutInflater mInflater;

    protected List<T> dataList;

    public SimpleExpandableAdapter(Context mContext,List<T> dataList){
        super();
        this.mContext = mContext;
        this.dataList = dataList;
        this.mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getGroupCount(){
        return dataList == null ? 0 : dataList.size();
    }

    @Override
    public T getGroup(int groupPosition){
        return dataList.get(groupPosition);
    }

    @Override
    public abstract int getChildrenCount(int groupPosition);

    @Override
    public abstract Object getChild(int groupPosition,int childPosition);

    @Override
    public long getGroupId(int groupPosition){
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition,int childPosition){
        return childPosition;
    }

    @Override
    public boolean hasStableIds(){
        return false;
    }

    @Override
    public abstract View getGroupView(int groupPosition,boolean isExpanded,View convertView,ViewGroup parent);

    @Override
    public abstract View getChildView(int groupPosition,int childPosition,boolean isLastChild,View convertView,ViewGroup parent);

    @Override
    public boolean isChildSelectable(int groupPosition,int childPosition){
        return true;
    }

    public List<T> getDataList(){
        return dataList;
    }

}
